package com.first.system.controller;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import com.first.common.pojo.CrmBanner;
import com.first.common.util.OssUtil;
import com.first.common.vo.Result;
import com.first.system.service.BannerService;
import com.first.system.vo.BannerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;
import java.io.ByteArrayInputStream;
import java.util.UUID;

/**
 * @program: first-project
 * @description:
 * @author: 闫锦超
 * @create: 2023-05-26 16:58
 **/
@RestController
@RequestMapping("/home/banner")
@Api(tags = "轮播管理")
public class BannerController {
    @Autowired
    private BannerService bannerService;
    @PostMapping("/getAllBanner/{currentPage}/{pageSize}")
    @ApiOperation(value = "获取所有的轮播图")
    public Result getAllBanner(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody BannerVo bannerVo){
            return bannerService.getAllBanner(currentPage,pageSize,bannerVo);
    }

    @PostMapping("/changeStatus/{id}/{isDisable}")
    @ApiOperation(value = "修改轮播的状态")
    public Result changeStatus(@PathVariable String id ,@PathVariable String isDisable){
       return bannerService.changeStatus(id,isDisable);
    }

    @PostMapping("uploadMsg")
    @ApiOperation(value = "上传图片")
    public String upload(@PathParam("file") MultipartFile file) {
       return OssUtil.uploadFile(file);
    }

    @PostMapping("/addBanner")
    @ApiOperation(value = "添加轮播图")
    public Result addBanner(@RequestBody CrmBanner crmBanner){
      return bannerService.addBanner(crmBanner);
    }

    @PostMapping("/deleteBanner")
    @ApiOperation(value = "删除轮播图")
    public Result deleteBanner(@RequestBody CrmBanner crmBanner){
       return bannerService.deleteBanner(crmBanner);
    }

}
